package com.lun.other.sort;

import java.util.Random;

public class IntArrayTools {
	
	/**
	 * 生成随机数数组
	 * 
	 * @param arrayLength
	 * @param bound
	 * @return
	 */
	public static int[] makeRandomIntArray(int arrayLength, int bound) {
		Random rand = new Random(System.nanoTime());
		int[] nums = new int[arrayLength];
		
		for(int i = 0; i < nums.length; i++) {
			nums[i] = rand.nextInt(bound);
		}
		return nums;
	}
	
	/**
	 * 生成递增数数组，如0, 1, 2, ..., length - 1
	 * 
	 * @param length
	 * @return
	 */
	public static int[] makeAscIntArray(int length) {
		int[] nums = new int[length];
		for(int i = 0; i < nums.length; i++) {
			nums[i] = i;
		}
		return nums;
	}
	
	/**
	 * 
	 * 交换数组两下标元素
	 * 
	 * @param nums
	 * @param i
	 * @param j
	 */
	public static void swap(int[] nums, int i, int j) {
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp;
	}
	
	/**
	 * 
	 * 打乱数组
	 * 
	 * @param nums
	 */
	public static void disorder(int[] nums) {
		Random rand = new Random(System.nanoTime());
		for(int i = 0; i < nums.length; i++) {
			int randIndex = rand.nextInt(nums.length);
			swap(nums, i, randIndex);
		}
	}
}
